package com.xr.org;

import java.util.Date;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.xr.common.CommUtil;

/**
 * comPayerViewModel
 */
public class comPayerViewModel extends DefaultViewModel {
  public void init(int state)
      throws Exception {
    // Add your code here
    super.init(state);
  }

  protected void initDataset(ViewDataset dataset)
      throws Exception {
    super.initDataset(dataset);
    // Add your code here
  }

  protected void initControl(Control control)
      throws Exception {
    super.initControl(control);
    // Add your code here
  }

  protected void initDatasets()
      throws Exception {
    super.initDatasets();
    // Add your code here
  }

  protected void initControls()
      throws Exception {
    super.initControls();
    // Add your code here
  }

  protected void doLoadData()
      throws Exception {
    // Add your code here
    super.doLoadData();
  }

  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
    // Add your code here
    super.doUpdateData(parameters, outParameters);
  }
  public void add(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  Dataset ds=getDataset("datasetComPayer");
	  DBStatement dbs = new DBStatement();
	  ds.setDate("CREATE_DATE", new Date());
	  CommUtil.dbsUpdateData(dbs, ds, "ORG_COMPANY", "COMPANY_ID","SEQ_ORG");
	  dbs.close();
 }
  public void modify(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  Dataset ds=getDataset("datasetComPayer");
	  DBStatement dbs = new DBStatement();
	  CommUtil.dbsUpdateData(dbs, ds, "ORG_COMPANY", "COMPANY_ID");
	  dbs.close();
 }
  public void dr(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  Dataset ds=getDataset("datasetComPayer");
	  DBStatement dbs = new DBStatement();
	  dbs.setSql("update org_company set dr=1,dr_date=sysdate,dr_id="+CommUtil.getEmployeeId()+" where INNER_COM=2 and company_id="+ds.getValue("COMPANY_ID"));
	  dbs.execute();
	  dbs.close();
 }
  
  public void storeList_del(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  Dataset ds=getDataset("datasetStore");
	  DBStatement dbs = new DBStatement();
	  dbs.setSql("update org_store set dr=1,dr_date=sysdate,dr_id="+CommUtil.getEmployeeId()+" where STORE_ID="+ds.getValue("STORE_ID"));
	  dbs.execute();
	  dbs.close();
 }
  
  public void storeList_submit(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  Dataset ds=getDataset("datasetStore");
	  DBStatement dbs = new DBStatement();
	  String rt="";
	  ds.moveFirst();
	  while(!ds.isLast()){
		  if(ds.getRecordState()==Record.STATE_NEW){
			  dbs.setSql("select count(1) from org_store where dr=0 and store_name ='"+ds.getString("STORE_NAME").trim()+"'");
			  if(dbs.query().getInt(0)>=1){
				  ds.setRecordState(Record.STATE_NONE);
				  rt+="["+ds.getString("store_name")+"]";
			  }
			  
		  }
		  if(ds.getRecordState()==Record.STATE_MODIFIED){
			  dbs.setSql("select count(1) from org_store where dr=0 and store_name ='"+ds.getString("STORE_NAME").trim()+"' and store_id<>"+ds.getString("STORE_ID"));
			  if(dbs.query().getInt(0)>=1){
				  ds.setRecordState(Record.STATE_NONE);
				  rt+="["+ds.getString("store_name")+"]";
			  }
			  
		  }
	 
		  ds.moveNext();
	  }
 
	  super.doUpdateData(parameters, outParameters);
	  dbs.close();
	  outParameters.setString("rt", rt);
 }
  
  
}
